package com.rc.saas.mini.service.rc;

import com.rc.saas.mini.mapper.rc.RcMemberGainRecordMapper;
import com.rc.saas.mini.model.rc.RcMemberGainRecord;
import com.rc.saas.mini.model.rc.RcMemberGainRecordExample;
import com.rc.saas.mini.model.rc.RcMemberGainSetting;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RcMemberGainRecordServiceImpl implements RcMemberGainRecordService {
    @Autowired
    private RcMemberGainRecordMapper rcMemberGainRecordMapper;

    @Override
    public RcMemberGainRecordMapper getMapper() {
        return rcMemberGainRecordMapper;
    }

    @Override
    public List<RcMemberGainRecord> listCurrentByMemberId(Long memberId) {
        RcMemberGainRecordExample example = new RcMemberGainRecordExample();
        example.createCriteria().andMemberIdEqualTo(memberId).andStatusEqualTo("0");
        example.setOrderByClause("created_time desc");
        return rcMemberGainRecordMapper.selectByExample(example);
    }

    @Override
    public void insertByList(List<RcMemberGainSetting> rcMemberGainSettingList, Long memberId) {
        for( RcMemberGainSetting rcMemberGainSetting:rcMemberGainSettingList){
            RcMemberGainRecord rcMemberGainRecord=new RcMemberGainRecord();
            BeanUtils.copyProperties(rcMemberGainSetting,rcMemberGainRecord);
            rcMemberGainRecord.setMemberId(memberId);
            rcMemberGainRecord.setCreatedTime(new Date());
            rcMemberGainRecord.setLastUpdatedTime(new Date());
            rcMemberGainRecordMapper.insertSelective(rcMemberGainRecord);
        }
    }
}
